/*
	CPU2 Communications
	Updated: 2/1/08
	
	Created By: Jared Bayne
	E-Mail:		JaredNBayne@gmail.com
	Created On:	February 1st, 2008

	Purpose:	This file will handle all of the communications
				to the CPU2.  


	CPU2 handles line sensor reading.  Although, it really can handle any type of digital
	sensor input.
	
	Here's the philosophy behind CPU2:
	
	CPU2 acts as one huge multiplexer.  An address is passed to it via the parallen connection.
	The address is a 6-bit binary number.
	
	The CPU2 then reads the multiplexer that corresponds to that line sensor.  It returns the data
	through the CPU2Data pin.  
	
	This is a digital system.  Only 1's and 0's can be sent over CPU2Data.
	
	If you wanted more info than that you would need to use some sort of serial connection.  This isn't
	possible with the current oscillator setup of CPU2.  Right now we are using the internal oscillator.
	This isn't nearly accurate enough to do serial communications.  I went through the calibration procedure
	of the oscillator, but it still isn't accurate enough.  Man, that caused me a lot of pain.  But, it all
	works now.
	

	UPDATE FOR 2008-2009:  Shouldn't need any updates, but won't know for sure until test.

*/

#define CPU2Add1	GET_BIT(PORTE).bit2
#define CPU2Add2	GET_BIT(PORTE).bit3
#define CPU2Add3	GET_BIT(PORTB).bit3
#define CPU2Add4	GET_BIT(PORTD).bit5
#define CPU2Add5	GET_BIT(PORTD).bit0
#define CPU2Add6	GET_BIT(PORTB).bit0

#define CPU2Data	GET_BIT(PIND).bit1

#define CPU1Add1	GET_BIT(PORTB).bit3
#define CPU1Add2	GET_BIT(PORTC).bit3
#define CPU1Add3	GET_BIT(PORTA).bit7
#define CPU1Add4	GET_BIT(PORTE).bit7



//Public Functions
void CPU2_SetAddress(int AddR);


//Private Functions



void CPU2_SetAddress(int AddR)
{
/*
	Function: 	CPU2_SetAddress
	
	Purpose:	This function will set the six address
				pins connected to the CPU2.
				
	INPUTS: Must send a 6 bit binary number (0-63)

	OUTPUTS: Address lines are set accordingly
*/

	//Displays a 6 bit binary number on the LCD
	int five=0, four=0, three=0, two=0, one=0, zero=0;
	
	//Breakdown the 6 bit binary number
	if ((AddR & 0b000001)==0b000001) zero=1;
	if ((AddR & 0b000010)==0b000010) one=1;
	if ((AddR & 0b000100)==0b000100) two=1;
	if ((AddR & 0b001000)==0b001000) three=1;
	if ((AddR & 0b010000)==0b010000) four=1;
	if ((AddR & 0b100000)==0b100000) five=1;
	
	//Set address pins accordingly
	CPU2Add1=zero;
	CPU2Add2=one;
	CPU2Add3=two;
	CPU2Add4=three;
	CPU2Add5=four;
	CPU2Add6=five;


}

